package SiTuQingYou.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import SiTuQingYou.dao.SceneDao;
import SiTuQingYou.dao.ScenePhotoDao;
import SiTuQingYou.util.Pager;
import SiTuQingYou.vo.Scene;

@WebServlet("/GetAllSceneServlet")
public class GetAllSceneServlet extends BaseAction {
	private static final long serialVersionUID = 1L;
    
    public GetAllSceneServlet() {
        super();
    }

    protected void getTopHotScene(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	String str=SceneDao.getscened().getTopSceneId();
    	PrintWriter out=resp.getWriter();
    	out.print(str);
		
	}
    protected void getTopHotPhoto(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String str=req.getParameter("str");
    String[] strs=new String[4];
    strs=str.split(",");
    String pics="";
    PrintWriter out=resp.getWriter();
    for(int i=0;i<strs.length;i++)
    {
    	int id=Integer.parseInt(strs[i]);
    	String pic=ScenePhotoDao.getspd().getfirstphotobyscenesid(id);
    	pics=pics+","+pic;
    }
    out.print(pics);
    	 
    	 
		
	}
	protected void getallscene(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Pager pager = Pager.init(request);
		ArrayList<Scene> scenes = SceneDao.getscened().allscene(pager);
		request.setAttribute("scenes",scenes );
		ArrayList<String> pics = new ArrayList<String>();
		
		for(int i=0;i<scenes.size();i++)
		{
			int id = scenes.get(i).getId();
			String pic = ScenePhotoDao.getspd().getfirstphotobyscenesid(id);
			pics.add(pic);
		}
		request.setAttribute("pics", pics);
	}
	
	
	
	@Override
	protected void doDefault(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stubr
		
	}

}
